﻿using System;
using System.Windows.Forms;

namespace Marmat.Forms
{
    internal partial class ComboBoxPopupForm : PopupControl
    {
        public ComboBoxPopupForm(ComboBox comboBox)
        {

            // 此调用是设计器所必需的。
            this.InitializeComponent();

            // 在 InitializeComponent() 调用之后添加任何初始化。
            this.comboBox = comboBox;
            this.panel1.BackColor = this.listBoxControl1.BackColor;
            //this.linkLabel2.BackColor = this.listBoxControl1.BackColor;
        }

        private readonly ComboBox comboBox;


        private void ListBoxControl1_Click(object sender, EventArgs e)
        {
            this.comboBox.SelectedValue = this.listBoxControl1.SelectedValue;
            this.CloseDropDown();
        }

        // Private Sub ListBoxControl1_SelectedIndexChanged(sender As Object, e As EventArgs) Handles ListBoxControl1.SelectedIndexChanged
        // If Me.OwnerEdit IsNot Nothing Then
        // ' CType(Me.OwnerEdit.Parent, BComboBox).SelectedIndex = ListBoxControl1.SelectedIndex
        // 'Me.ComboBox.SelectedIndex = ListBoxControl1.SelectedIndex
        // End If
        // End Sub

        private void ListBoxControl1_CustomItemDisplayText(object sender, DevExpress.XtraEditors.CustomItemDisplayTextEventArgs e)
        {
            var info = new CustomDisplayTextEventArgs(e.Value, e.DisplayText);
            this.comboBox.RaiseEventCustomDisplayText(info);
            e.DisplayText = info.DisplayText;
        }

        private void ListBoxControl1_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode == Keys.Enter)
            {
                this.ListBoxControl1_Click(this.listBoxControl1, EventArgs.Empty);
            }
        }

        private void LinkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            this.comboBox.RaiseCustomCreateItemClick();
        }

        private void linkLabel2_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
        {
            this.comboBox.SelectedValue = null;
            this.CloseDropDown();
        }
    }
}